package inits

import (
	"fmt"
	"github.com/go-redis/redis/v8"
	"log"
	"red/appconfig"
	"red/global"
)

func Redis() {
	data := appconfig.Config.Redis
	addr := fmt.Sprintf("%s:%d", data.Host, data.Port)
	global.Rdb = redis.NewClient(&redis.Options{
		Addr:     addr,
		Password: "052A73AC8C5671BD2AAB6B8F18903E12", // no password set
		DB:       0,                                  // use default DB
	})

	err := global.Rdb.Set(global.Ctx, "key", "value", 0).Err()
	if err != nil {
		panic(err)
	}
	log.Println("redis 连接成功")
}
